<?php

namespace App\Morefun\Quiz;

use App\Contracts\Repositories\Quiz\SheetRepository as SheetRepositoryContracts;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;

class SheetService
{
    public $sheets;

    public function __construct(SheetRepositoryContracts $sheets)
    {
        $this->sheets = $sheets;
    }

    public function formatSheets($paperId, Request $request)
    {
        $records = [];
        $now = Carbon::now()->toDateTimeString();
        $sheets = $request->json('sheets', []);
        $activityId = $request->json('activity_id', '');

        foreach ($sheets as $sheet) {
            $records[] = [
                'paper_id' => $paperId,
                'activity_id' => $activityId,
                'quiz_id' => Arr::get($sheet,'quiz_id', ''),
                'option_id' => \GuzzleHttp\json_encode(Arr::get($sheet, 'option_id', [])),
                'fill_content' => \GuzzleHttp\json_encode(Arr::get($sheet, 'fill_content', [])),
                'created_at' => $now,
            ];
        }

        return $records;
    }
}